package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.TrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


//品牌
@RestController
@RequestMapping("/admin/product/baseTrademark")
@Api(tags="base_trademark:品牌列表的单表操作")
public class TrademarkController {

    @Autowired
    private TrademarkService trademarkService;

    /**
     * /admin/product/baseTrademark/{page}/{limit}_1660293796171
     * 品牌管理之分页列表
     * Get
     */
    @GetMapping("/{page}/{limit}")
    @ApiOperation("品牌管理之分页列表")
    public Result baseTrademark(
            @PathVariable Long page,
            @PathVariable Long limit
    ){
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage page1 = trademarkService.page(baseTrademarkPage, null);
        return Result.ok(page1);
    }

    /**
     * /admin/product/baseTrademark/save
     * 新增数据
     * Post
     */
    @PostMapping("/save")
    @ApiOperation("新增数据")
    public Result save(
            @RequestBody BaseTrademark baseTrademark
    ){
        trademarkService.save(baseTrademark);
        return Result.ok();
    }



    /**
     * /admin/product/baseTrademark/get/{id}
     * 修改接口之数据回显
     * get
     */
    @GetMapping("/get/{id}")
    @ApiOperation("修改接口值数据回显")
    public Result baseTrademark(@PathVariable Long id){
        BaseTrademark baseTrademarkById = trademarkService.getById(id);
        return Result.ok(baseTrademarkById);
    }

    /**
     * /admin/product/baseTrademark/update
     * 修改接口之数据更新
     * Put
     */
    @PutMapping("/update")
    @ApiOperation("修改接口之数据更新")
    public Result update(
            @RequestBody BaseTrademark baseTrademark
    ){
        //修改
        trademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * /admin/product/baseTrademark/remove/{id}
     * 删除
     * Delete
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation("删除")
    public Result delete(@PathVariable Long id){
        trademarkService.removeById(id);
        return Result.ok();
    }

}
